/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

package wads.drawing.node;

import wads.drawing.line.CaseLink;
import wads.app.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class DocumentNode extends CaseNode{
//  private static final long serialVersionUID = -774069428446405485L;
  
//  private Properties docProp;
  private transient BaseWADDialog wNodeDialog;

//  public static final String DOCUMENT_NAME_KEYNAME = "name";
//  public static final String DOCUMENT_PATH_KEYNAME = "docPath";
  public static final String DOCUMENT_XPDL_VERSION = "XPDLVersion";
  private String XPDLVersion;
  public static final String DOCUMENT_VENDER = "Vender";
  private String vender;
  public static final String DOCUMENT_CREATED = "Created";
  private String created;
  public static final String DOCUMENT_DESCRIPTION = "Description"; //maybe use this instead of 'name'
  private String description;
  public static final String DOCUMENT_DOCUMENTATION = "Documentation"; //maybe use this instead of 'docPath'
  private String documentation;
  private String prototypePath;
  private String documentId;

  private ImageIcon icon = new ImageIcon("images/document.png");
//  public static final int DEFAULT_DOC_ICON_WIDTH = 32;
//  public static final int DEFAULT_DOC_ICON_HEIGHT = 32;
  private int gap = 20;

  public DocumentNode(Point anchor) {
    super(anchor, "[ Unregisted Document ]");
    
    id = ++idCount;
//    ((DocumentNodeDialog)wNodeDialog).setCurrentDirectory(new File(WADTools.FORM_PATH));
//    docProp = new Properties();

//    super.initContent();
    setWidth(DEFAULT_NODE_ICON_WIDTH);
    setHeight(DEFAULT_NODE_ICON_HEIGHT);
  }

//  @Override
//  public CaseNodeDialog createDialog(){ return null; }

  @Override
  public String toString() {
    String connLinks = "(";
    for(CaseLink connLink: getConnectedLinks()) {
      connLinks += ("*"+connLink.getId()+" ");
    }
    connLinks += ")";
    
    return "[Node ID: "+getId()
            +", Document name: "+getName()
            +", Connect links: "+connLinks
            +"]";
  }
  
  @Override
  protected void draw(Graphics2D g2d){
    
    //Init normal box dimension
    int normBoxWidth = CaseNode.DEFAULT_NODE_ICON_WIDTH;
    int normBoxHeight = CaseNode.DEFAULT_NODE_ICON_HEIGHT;

    //Init the big box dimension
    //int bigBoxWidth=0;
    //int bigBoxHeight=0;

    //Init small box height
    int smallBoxHeight = 15;
    //int smallBoxWidth = 40;

    //Init big box min height
    //int minBigBoxHeight = 30;

    //Init ascender line
    //int ascLineStartX = this.x + 2*this.gap;
    int ascLineStartY = getStartY() + smallBoxHeight + this.gap;

    //Get the text bounds
    g2d.setColor(Color.black);
    drawTextAlign(g2d, this.getName(), ascLineStartY+10, this.gap);

    setNodeShapeBounds2D(getStartX(), getStartY(), DEFAULT_NODE_ICON_WIDTH, DEFAULT_NODE_ICON_HEIGHT);
    removeAllComponents();

    Rectangle2D box = new Rectangle2D.Float(getStartX(), getStartY(), normBoxWidth, normBoxHeight);
    append(box);
    g2d.drawImage(icon.getImage(), getStartX(), getStartY(), DEFAULT_NODE_ICON_WIDTH, DEFAULT_NODE_ICON_HEIGHT, icon.getImageObserver());

    super.draw(g2d);
  }

  //add for specific dialog ability
  //the code of following two methods is the same in any WADCaseNode
  //this method is Override to CaseNode.showDialog()
  @Override
  public void showDialog(CaseEditor pf) {
    wNodeDialog = new DocumentNodeDialog(pf, this);
//    wNodeDialog.setProperties(this.getDocProp());
    //wNodeDialog.initDisplay();
    //Set the dialog of this node
    //nodeDialog is declared in CaseNode
    if((wNodeDialog != null) && (wNodeDialog instanceof BaseWADDialog)) {
      //init the displaying properties
//      wNodeDialog.setProperties(this.getDocProp());
      wNodeDialog.initDisplay();
      wNodeDialog.setVisible(true);
    }
  }

  @Deprecated
  @Override
  public void closeDialog(int returnValue) {
    if(returnValue==JOptionPane.OK_OPTION) {
//        this.setDocProp(wNodeDialog.getProperties());
    }
  }

    /**
     * @return the docProp
     */
//    public Properties getDocProp() {
//        return docProp;
//    }

    /**
     * @param docProp the docProp to set
     */
//    public void setDocProp(Properties docProp) {
//        this.docProp = docProp;
//    }

    /**
     * @return the prototypePath
     */
    public String getPrototypePath() {
        return prototypePath;
    }

    /**
     * @param prototypePath the prototypePath to set
     */
    public void setPrototypePath(String prototypePath) {
        this.prototypePath = prototypePath;
//        ((DocumentNodeDialog)wNodeDialog).setCurrentDirectory(new File(prototypePath).getParentFile());
    }

    /**
     * @return the XPDLVersion
     */
    public String getXPDLVersion() {
        return XPDLVersion;
    }

    /**
     * @param XPDLVersion the XPDLVersion to set
     */
    public void setXPDLVersion(String XPDLVersion) {
        this.XPDLVersion = XPDLVersion;
    }

    /**
     * @return the vender
     */
    public String getVender() {
        return vender;
    }

    /**
     * @param vender the vender to set
     */
    public void setVender(String vender) {
        this.vender = vender;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the documentation
     */
    public String getDocumentation() {
        return documentation;
    }

    /**
     * @param documentation the documentation to set
     */
    public void setDocumentation(String documentation) {
        this.documentation = documentation;
    }

    /**
     * @return the created
     */
    public String getCreated() {
        return created;
    }

    /**
     * @param created the created to set
     */
    public void setCreated(String created) {
        this.created = created;
    }

    /**
     * @return the documentId
     */
    public String getDocumentId() {
        return documentId;
    }

    /**
     * @param documentId the documentId to set
     */
    public void setDocumentId(String documentId) {
        this.documentId = documentId;
    }

}